using System;
using System.Collections.Generic;
using System.Text;
using System.Windows.Forms;
using System.Collections;
using TaskManager.Common;
using System.Text.RegularExpressions;
using System.Threading;
using System.IO;
using Tools;
using TaskManager.TaskBase;


namespace TaskManager.WebTask
{
    public class Jk123Manage : WebTaskManager
    {
        override protected void InitTaskList()
        {
            for (int i = 870; i < 890; i++)
            {
                //IExecuteTask et = (IExecuteTask)new Jk123Execute("http://www.jk123.com/product.aspx?id=" + i.ToString());
                IExecuteTask et = (IExecuteTask)new Jk123Execute("http://www.jk123.com/html/product/product-" + i.ToString() + ".html");
                et.TaskFinish += OnTaskFinish;
                et.TaskRunning += OnTaskRunning;
                WaitingList.Add(et);
            }

        }
    }

    public class Jk123Execute : WebExecuteTask
    {

        public Jk123Execute(string url):base(url)
        {  
        }
        override protected int ProcessTask()
        {
            Encoding _PageEncode = Encoding.GetEncoding(@"utf-8");
            string TargetUrl = m_WebUri.ToString();
            Stream webContent = Tools.WebUtility.GetStreamFromUrl(TargetUrl, 10 * 1000);
            StreamReader sr = new StreamReader(webContent, _PageEncode);
            string _PageContent = sr.ReadToEnd();
            _PageContent = _PageContent.Replace("\"", "");
            _PageContent = _PageContent.Replace("\'", "");

            RegexOptions option = (RegexOptions.Singleline | RegexOptions.IgnorePatternWhitespace | RegexOptions.ExplicitCapture | RegexOptions.IgnoreCase);
            string regex = @"<title>(?<Title>.{0,200})</title>";
            string field = @"Title";
            string NewsTitle = RegTools.GetContentByReg(_PageContent, regex, field, option);
            return 1;
        }
    
    }
}
